{% extends "base_generic.html" %}

{% block title %}
  {% if form.instance.pk %}Edit Book{% else %}Add Book{% endif %} - Local Library
{% endblock %}

{% block content %}
<div class="row justify-content-center">
  <div class="col-md-8">
    <div class="card">
      <div class="card-header">
        <h3 class="mb-0">
          <i class="bi bi-book"></i>
          {% if form.instance.pk %}
            Edit Book: {{ form.instance.title }}
          {% else %}
            Add New Book
          {% endif %}
        </h3>
      </div>
      <div class="card-body">
        <form method="post">
          {% csrf_token %}
          
          {% if form.non_field_errors %}
            <div class="alert alert-danger">
              {{ form.non_field_errors }}
            </div>
          {% endif %}
          
          <div class="mb-3">
            <label for="{{ form.title.id_for_label }}" class="form-label">Title *</label>
            {{ form.title }}
            {% if form.title.errors %}
              <div class="text-danger">{{ form.title.errors }}</div>
            {% endif %}
          </div>
          
          <div class="mb-3">
            <label for="{{ form.author.id_for_label }}" class="form-label">Authors *</label>
            {{ form.author }}
            {% if form.author.errors %}
              <div class="text-danger">{{ form.author.errors }}</div>
            {% endif %}
            <div class="form-text">Hold Ctrl (Cmd on Mac) to select multiple authors</div>
          </div>
          
          <div class="mb-3">
            <label for="{{ form.summary.id_for_label }}" class="form-label">Summary *</label>
            {{ form.summary }}
            {% if form.summary.errors %}
              <div class="text-danger">{{ form.summary.errors }}</div>
            {% endif %}
          </div>
          
          <div class="row">
            <div class="col-md-6">
              <div class="mb-3">
                <label for="{{ form.isbn.id_for_label }}" class="form-label">ISBN *</label>
                {{ form.isbn }}
                {% if form.isbn.errors %}
                  <div class="text-danger">{{ form.isbn.errors }}</div>
                {% endif %}
              </div>
            </div>
            <div class="col-md-6">
              <div class="mb-3">
                <label for="{{ form.publication_date.id_for_label }}" class="form-label">Publication Date</label>
                {{ form.publication_date }}
                {% if form.publication_date.errors %}
                  <div class="text-danger">{{ form.publication_date.errors }}</div>
                {% endif %}
              </div>
            </div>
          </div>
          
          <div class="mb-3">
            <label for="{{ form.genre.id_for_label }}" class="form-label">Genres</label>
            {{ form.genre }}
            {% if form.genre.errors %}
              <div class="text-danger">{{ form.genre.errors }}</div>
            {% endif %}
            <div class="form-text">Hold Ctrl (Cmd on Mac) to select multiple genres</div>
          </div>
          
          <div class="d-flex justify-content-between">
            <a href="{% url 'books' %}" class="btn btn-secondary">
              <i class="bi bi-arrow-left"></i> Cancel
            </a>
            <button type="submit" class="btn btn-primary">
              <i class="bi bi-save"></i>
              {% if form.instance.pk %}Update Book{% else %}Add Book{% endif %}
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
{% endblock %}